package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.PmspurchaseapplylineApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.*;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.dao.ReqLineDao;
import com.clickpaas.materialsprocurement.entity.ReqLineEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Repository
public class ReqLineDaoImpl implements ReqLineDao {

    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private PmspurchaseapplylineApi pmspurchaseapplylineApi;

    /**
     * 根据条件查询物料数据
     *
     * @param reqLineEntity
     * @return List<PMSpurchaseApplyLineDTO1>
     */
    @Override
    public List<PMSpurchaseApplyLineDTOResponse> getReLineByCondtion(ReqLineEntity reqLineEntity) {
        PMSpurchaseApplyLineDTO pmSpurchaseApplyLineDTO = materalsDtoBean.pmSpurchaseApplyLineDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(reqLineEntity,pmSpurchaseApplyLineDTO);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",reqLineEntity);
            return null;
        }
        return queryMaterialsInfo(pmSpurchaseApplyLineDTO);
    }

    /**
     * 查询后台
     * @param pmSpurchaseApplyLineDTO
     * @return
     */
    private List<PMSpurchaseApplyLineDTOResponse> queryMaterialsInfo(PMSpurchaseApplyLineDTO pmSpurchaseApplyLineDTO){
        DataResponseListPMSpurchaseApplyLineDTO pmsPurchaseApplyLineUsingPOST = pmspurchaseapplylineApi.findPMSPurchaseApplyLineUsingPOST(pmSpurchaseApplyLineDTO);
        if(null == pmsPurchaseApplyLineUsingPOST
                || null == pmsPurchaseApplyLineUsingPOST.getData()
                || pmsPurchaseApplyLineUsingPOST.getData().size()<=0
                || !"SUCCESS".equals(pmsPurchaseApplyLineUsingPOST.getMessage())){
            log.info("当前查询的数据：【{}】",pmsPurchaseApplyLineUsingPOST);
            return null;
        }
        return pmsPurchaseApplyLineUsingPOST.getData();
    }
}
